<template>
  <div class="organization-management">
    <el-card class="header-card">
      <template #header>
        <div class="card-header">
          <span>组织管理</span>
        </div>
      </template>
      <div class="content">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="组织列表" name="list">
            <div class="toolbar">
              <el-button type="primary" @click="handleCreate">新增组织</el-button>
              <el-button @click="handleRefresh">刷新</el-button>
            </div>
            <el-table :data="organizations" style="width: 100%" v-loading="loading">
              <el-table-column prop="name" label="组织名称" width="200" />
              <el-table-column prop="status" label="状态" width="100">
                <template #default="scope">
                  <el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'">
                    {{ scope.row.status === 'active' ? '正常' : '停用' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="createdAt" label="创建时间" width="180" />
              <el-table-column label="操作">
                <template #default="scope">
                  <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                  <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="组织审核" name="audit">
            <el-table :data="auditList" style="width: 100%">
              <el-table-column prop="name" label="组织名称" width="200" />
              <el-table-column prop="applicant" label="申请人" width="150" />
              <el-table-column prop="applyTime" label="申请时间" width="180" />
              <el-table-column label="操作">
                <template #default="scope">
                  <el-button link type="primary" @click="handleApprove(scope.row)">通过</el-button>
                  <el-button link type="danger" @click="handleReject(scope.row)">拒绝</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const activeTab = ref('list')
const loading = ref(false)

// 模拟组织数据
const organizations = ref([
  {
    id: 1,
    name: '北京分公司',
    status: 'active',
    createdAt: '2023-01-15 10:30:00'
  },
  {
    id: 2,
    name: '上海分公司',
    status: 'active',
    createdAt: '2023-02-20 14:45:00'
  },
  {
    id: 3,
    name: '广州分公司',
    status: 'inactive',
    createdAt: '2023-03-10 09:15:00'
  }
])

// 模拟审核数据
const auditList = ref([
  {
    id: 1,
    name: '深圳分公司',
    applicant: '张三',
    applyTime: '2023-04-01 11:20:00'
  },
  {
    id: 2,
    name: '杭州分公司',
    applicant: '李四',
    applyTime: '2023-04-05 16:30:00'
  }
])

// 方法
const handleCreate = () => {
  console.log('新增组织')
}

const handleRefresh = () => {
  console.log('刷新组织列表')
}

const handleEdit = (row: any) => {
  console.log('编辑组织', row)
}

const handleDelete = (row: any) => {
  console.log('删除组织', row)
}

const handleApprove = (row: any) => {
  console.log('通过审核', row)
}

const handleReject = (row: any) => {
  console.log('拒绝审核', row)
}
</script>

<style scoped>
.organization-management {
  padding: 20px;
}

.header-card {
  margin-bottom: 20px;
}

.card-header {
  font-size: 18px;
  font-weight: bold;
}

.toolbar {
  margin-bottom: 20px;
}

.toolbar .el-button {
  margin-right: 10px;
}
</style>